class Solution:
    def canReach(self, arr: list, start: int) -> bool:
        queue = [start]
        visited = set()
        while queue:
            n = queue.pop(0)
            visited.add(n)
            if n - arr[n] >= 0:
                if arr[n - arr[n]] == 0:
                    return True
                if (n - arr[n]) not in visited:
                    queue.append(n - arr[n])
            if n + arr[n] < len(arr):
                if arr[n + arr[n]] == 0:
                    return True
                if (n + arr[n]) not in visited:
                    queue.append(n + arr[n])

        return False


if __name__ == "__main__":
    print(Solution().canReach(arr=[3, 0, 2, 1, 2], start=2))
